<?php
class ModelPromobanner
{
	public function addpromobanner($filename)
	{
		 $sql1 = "SELECT COUNT(promobanner_id) AS IMGCOUNT
				 FROM tbl_promobanner
				 WHERE filename = '" . $filename . "' ";
		
		$rs = DB::fetchRow($sql1);
		$rw_count = $rs['IMGCOUNT'];
		if($rw_count == 0)
		{
			$sql2 = "INSERT INTO tbl_promobanner(filename, status)
					VALUES('" . $filename . "', 1)";
			$add_Promobanner = DB::exec($sql2);
			if($add_Promobanner)
			{
				echo "success";
			}
		} else {
			echo "error";
		}
	}
	
	public function getpromobannerImages()
	{
		$sql = "SELECT *
				FROM tbl_promobanner";
		
		$Promobanner_arr = DB::fetchAll($sql);
		//print_r($Promobanner_arr);
		return $Promobanner_arr;
	}
	
	public function delPromoImage($promo_id)
	{
		$sql1 = "SELECT filename
				 FROM tbl_promobanner
				 WHERE promobanner_id = " . $promo_id;
		
		$rs = DB::fetchRow($sql1);
		
		$del_thumb = unlink("../images/promobanner/thumbs/" . $rs['filename']);
		$del_large = unlink("../images/promobanner/" . $rs['filename']);
		if($del_large)
		{
			$sql2 = "DELETE FROM tbl_promobanner
					 WHERE promobanner_id = " . $promo_id;
			echo $sql2;
			$del_img = DB::exec($sql2);
			if($del_img)
			{
				echo "Selected image has been delete from the Promobanner";
			}
		}
	}

        function updatepromourl($request)
        {
            $sql="update tbl_promobanner set url='".$request["url"]."' where promobanner_id=".$request["promo_id"]."";
           // echo $sql;
            $update=DB::exec($sql);
            if($update){
                echo "<span class='success'>URL update successfully</span>";
            }
        }

          function updatepromonewwindow($request)
        {
              if(!isset($request["isnewwindowval"])|| $request["isnewwindowval"]==""){
                   $checked='';
              }
              else{
                  $checked=$request["isnewwindowval"];
              }
            $sql="update tbl_promobanner set newwindow='".$checked."' where promobanner_id=".$request["promoid"]."";
           //echo $sql;
            $update=DB::exec($sql);
            if($update){
                echo "<span class='success'>Target updated successfully</span>";
            }
        }
}
?>